
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no, email=no">
    <meta content="fullscreen=yes,preventMove=no" name="ML-Config" />
    <meta http-equiv="content-language" content="zh-CN" />
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta name="keywords" content="家电销售">
    <meta name="description" content="冰箱、空调、电视、洗衣机">
    <title>未接订单</title>
    <script src="./js/common.js"></script>
    <script src="./js/jquery.min.js"></script>
    <link rel="stylesheet" href="./js/need/layer.css">
    <script src="./js/layer.js"></script>
    <script src="./js/fastclick.js"></script>
    <script src="./js/rt.0.5.1.min.js"></script>
    <link rel="stylesheet" href="./css/newOrder.css?v=10">
</head>
<body>

<ul class="orderBox">

</ul>
<div class="norecord" style="display: block;">
    <img src="./images/norecord.png" alt="">
    <span>暂无订单</span>
</div>

<script>
    $(function(){
        FastClick.attach(document.body);
        var defaultParam={
            page:1,
            size:20
        };
        $.ajax({
            type: urlType,
            url: "/user-order/is-service",
            data: {
            },
            dataType: "json",
            success: function (res) {
                if(res.code==200){
                    var status = res.data;
                    if(status==0){
                        layer.open({
                            content:'您还有没权限',
                            btn:'确定'
                        })
                    }else{
                        getList(defaultParam.page,defaultParam.size);
                    }
                }else{
                    layer.open({
                        content:res.message,
                        btn:'确定'
                    })
                }
            },
            error: function () {
            }
        });

        //获取订单列表
        function getList(page,size){
            $.ajax({
                type: urlType,
                url: "/user-order/show-list",
                data: {
                    menu : 'missed',
                    page_index:page,
                    page_size:size
                },
                dataType: "json",
                success: function (res) {
                    console.log(typeof res.data);
                    if(res.code==200){
                        var list = res.data;
                        if(list.length==0){
                            if(defaultParam.page==1){
                                $('.norecord').show();
                                return;
                            }else{
                                return;
                            }
                        }
                        var str = '';
                        for(var i=0;i<list.length;i++){
                            if((list[i].type)==2){
                                str+='<li class="ordertwo" data-id="'+list[i].id+'">'+list[i].id+'</li>';
                            }else {
                                str+='<li class="order" data-id="'+list[i].id+'">'+list[i].id+'</li>';
                            }
                        }
                        $('.orderBox').append(str);
                    }else{
                        layer.open({
                            content:res.message,
                            btn:'确定'
                        })
                    }
                },
                error: function () {
                }
            });
        }

        //点击订单查看详情1
        $(document).on('click','.orderBox li',function(){
            var id=$(this).data('id');
            $.ajax({
                type: urlType,
                url: "/user-order/missed-order-detail",
                data: {
                    orderId:id
                },
                dataType: "json",
                success: function (res) {
                    if(res.code==200){
                        var data = res.data[0];
                        console.log(data.is_rob);
                        var tpl = $('#neworder').html();
                        var html = rt.template(tpl, data);
                        var page = layer.open({
                            type: 1
                            ,content: html
                            ,anim: 'up'
                            ,shadeClose: false
                            ,style: 'position:fixed; left:0; bottom:0; width:100%; height:auto; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'
                        });
                    }else{
                        layer.open({
                            content:res.message,
                            btn:'确定'
                        })
                    }
                },
                error: function () {
                }
            });
        });

        //关闭订单详情
        $(document).on('click','.layui-m-layershade',function(){
            layer.closeAll();
        });

        //接单
        $(document).on('click','.accept',function(){
            var id=$(this).data('id');
            layer.open({
                content:'确认接受？',
                btn:['确定','取消'],
                yes: function(index){
                    //location.reload();
                    $.ajax({
                        type: urlType,
                        url: "/user-order/meet",
                        data: {
                            order_id : id
                        },
                        dataType: "json",
                        success: function (res) {
                            console.log(res);
                            if(res.code==200){
                                layer.closeAll();
                                layer.open({
                                    content: '接单成功'
                                    ,skin: 'msg'
                                    ,time: 2 //2秒后自动关闭
                                });
                                $('.orderBox [data-id='+id+']').remove();
                            }else{
                                layer.open({
                                    content:res.message,
                                    btn:'确定'
                                })
                            }
                        },
                        error: function () {
                        }
                    });
                    layer.close(index);
                }
            });
        });

        //拒绝
        $(document).on('click','.refuse',function(){
            var id=$(this).data('id');
            layer.open({
                content:'确认拒绝？',
                btn:['确定','取消'],
                yes: function(index){
                    //location.reload();
                    $.ajax({
                        type: urlType,
                        url: "/user-order/refuse",
                        data: {
                            order_id : id
                        },
                        dataType: "json",
                        success: function (res) {
                            console.log(res);
                            if(res.code==200){
                                layer.closeAll();
                                layer.open({
                                    content: '拒绝成功'
                                    ,skin: 'msg'
                                    ,time: 2 //2秒后自动关闭
                                });
                                $('.orderBox [data-id='+id+']').remove();
                            }else{
                                layer.open({
                                    content:res.message,
                                    btn:'确定'
                                })
                            }
                        },
                        error: function () {
                        }
                    });
                    layer.close(index);
                }
            });
        });


    });

</script>
<script type="text/html" id="neworder">
    <div class="orderMsg">
        <div class="orderTitleNew"><%=it.category%>/<%=it.brand%>/<%=it.model_number%></div>
        <ul  class="msgList">
            <li>
                <div class="orderItem">订单编号</div>
                <div class="orderDetail"><%=it.id%></div>
            </li>
            <li>
                <div class="orderItem">用户姓名</div>
                <div class="orderDetail"><%=it.user_name%></div>
            </li>
            <li>
                <div class="orderItem">商品容量</div>
                <div class="orderDetail"><%=it.capacity%></div>
            </li>
            <li>
                <div class="orderItem">商品型号</div>
                <div class="orderDetail"><%=it.model_number%></div>
            </li>
            <li>
                <div class="orderItem">商品成色</div>
                <div class="orderDetail"><%=it.condition%></div>
            </li>
            <li>
                <div class="orderItem">结算价格</div>
                <div class="orderDetail"><%=(parseInt(it.reserve_price)/100)%>元</div>
            </li>
            <li>
                <div class="orderItem">配送地址</div>
                <div class="orderDetail"><%=it.province_name+' '+it.city_name+' '+it.area_name%></div>
            </li>
            <li>
                <div class="orderItem">用户电话</div>
                <div class="orderDetail">
                    <%=it.mobile.substr(0,3)+'****'+it.mobile.substr(7,4)%>
                </div>
            </li>
            <li>
                <div class="orderItem">备注</div>
                <div class="orderDetail"><%=it.remarks%></div>
            </li>
        </ul>
        <div class="orderOperate">
            <div data-id="<%=it.id%>" class="refuse">拒绝</div>
            <div data-id="<%=it.id%>" class="accept">接受</div>
        </div>
    </div>
</script>

</body>
</html>
